<template>
  <ScreenAdapter>
    <div class="bg">
      <!--  页面顶部   -->
      <Part2_top/>
      <main>
        <!--  页面右侧   -->
        <Part2_right ref="refRight"/>
        <!--  页面左侧   -->
        <Part2_left ref="refLeft"/>
        <!--  页面中部    -->
        <Part2_middle ref="refCenter" @getAreaCode="setAreaCode" @getDataYear="setDataYear"/>
      </main>
    </div>
  </ScreenAdapter>
</template>

<script>
import ScreenAdapter from '../components/ScreenAdapter';
import Part2_top from "../components/Part2_top";
import Part2_left from "../components/Part2_left";
import Part2_right from "../components/Part2_right";
import Part2_middle from "../components/Part2_middle";
import axios from "_axios@0.25.0@axios";
import api from "@/api/gs";

const echarts = require('echarts')
const echartsGl = require('echarts-gl')
const Highcharts = require('highcharts')

export default {
  name: "index",
  components: {
    ScreenAdapter, Part2_top, Part2_left, Part2_right, Part2_middle
  },
  data() {
    return {
      // 统筹区编码
      areaCode: '330799',
      // 数据年份
      year: '2021',
      // 当前月的上月往前推6个月的月份
      firstMonth: '',
      // 当前月的上月
      lastMonth: '',
    }
  },
  mounted() {
    this.initMonth();
    this.initDataRight();
    this.initDateCenter();
    this.initDataLeft();
  },
  methods: {
    // 月份初始化
    initMonth() {
      const date = new Date();
      let year = date.getFullYear();
      const lastMonthTemp = date.getMonth();
      this.lastMonth = year + ('' + lastMonthTemp).padStart(2, '0');
      let firstMonthTemp = lastMonthTemp - 5;
      if (firstMonthTemp <= 0) {
        year -= 1;
        this.firstMonth = '' + year + ('' + (12 + parseInt(firstMonthTemp))).padStart(2, '0');
      }
    },
    // 数据初始化--主屏右侧图表
    initDataRight() {
      //this.initCaseRegionCycle();
      //this.initFund();
      this.initRdAndJdAmount();
      //this.initCooperationHandle();
      this.initFundRankRegion();
    },
    // 数据初始化--主屏左侧图表
    initDataLeft() {
      this.initFundRankIndustry();
      this.initCaseRankArea();
      this.initCooperationHandle();
    },
    // 数据初始化--主屏中部图表
    initDateCenter() {
      this.initFundSettlement();
      this.initCooperation();
      this.initCaseRegion();
    },
    // 初始化图表数据--案件数事故率
    initCaseRegion() {
      const url = api.getCaseRegion;
      if (url) {
        let param = {};
        param.areaCode = this.areaCode;
        param.year = this.year;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--案件数事故率--错误!');
            console.log(res.data);
          }
          this.$refs.refCenter.initCasesInfo(res.data.result);
        }).catch(err => {});
      }
    },
    // 初始化图表数据--基金收支情况
    initFund() {
      const url = api.getFund;
      if (url) {
        let param = {};
        param.areaCode = this.areaCode;
        param.startYear = this.firstMonth;
        param.endYear = this.lastMonth;
        param.typeFlag = 'M';
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--基金收支情况--错误!');
            console.log(res.data);
          }
          this.$refs.refRight.initFund(res.data.result);
        }).catch(err => {});
      } else {
        this.$refs.refRight.initFund();
      }
    },
    // 初始化图表数据--工伤鉴定与认定数查询
    initRdAndJdAmount() {
      const url = api.getRdAndJdAmount;
      if (url) {
        let param = {};
        param.areaCode = this.areaCode;
        param.startYear = this.firstMonth;
        param.endYear = this.lastMonth;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--工伤鉴定与认定数查询--错误!');
            console.log(res.data);
          }
          this.$refs.refRight.initRdAndJdAmount(res.data.result);
        }).catch(err => {});
      }
    },
    // 初始化图表数据--案件办理平均周期
    initCaseRegionCycle() {
      const url = api.getCaseRegionCycle;
      if (url) {
        let param = {};
        param.year = this.year;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--案件办理平均周期--错误!');
            console.log(res.data);
          }
          this.$refs.refRight.initCaseRegionCycle(res.data.result);
        }).catch(err => {});
      } else {
        this.$refs.refRight.initCaseRegionCycle();
      }
    },
    // 初始化图表数据--案件处置协同
    initCooperationHandle() {
      const url = api.getCooperationHandle;
      if (!url) {
        let param = {};
        param.areaCode = this.areaCode;
        param.startYear = this.firstMonth;
        param.endYear = this.lastMonth;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--案件处置协同--错误!');
            console.log(res.data);
          }
          this.$refs.refLeft.initCooperationHandle(res.data.result, 600);
        }).catch(err => {});
      } else {
        this.$refs.refLeft.initCooperationHandle();
      }
    },
    // 初始化图表数据--支付能力排行
    initFundRankRegion() {
      const url = api.getFundRankRegion;
      if (url) {
        let param = {};
        param.areaCode = '330700'
        param.year = this.year;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--支付能力排行--错误!');
            console.log(res.data);
          }
          this.$refs.refRight.initFundRankRegion(res.data.result);
        }).catch(err => {});
      } else {
        this.$refs.refRight.initFundRankRegion();
      }
    },
    // 初始化图表数据--事故案件分布
    initFundRankIndustry() {
      const url = api.getCaseRankIndustry;
      if (url) {
        let param = {};
        param.areaCode = this.areaCode;
        param.year = this.year;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--事故案件分布--错误!');
            console.log(res.data);
          }
          this.$refs.refLeft.initCaseRankIndustry(res.data.result);
        }).catch(err => {});
      } else {
        this.$refs.refLeft.initCaseRankIndustry();
      }
    },
    // 初始化图表数据--案件区域排名
    initCaseRankArea() {
      const url = api.getCaseRankArea;
      if (url) {
        let param = {};
        param.year = this.year;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--案件区域排名--错误!');
            console.log(res.data);
          }
          this.$refs.refLeft.initCaseRankArea(res.data.result);
        }).catch(err => {});
      } else {
        this.$refs.refLeft.initCaseRankArea();
      }
    },
    // 初始化图表数据--工伤联网结算
    initFundSettlement() {
      const url = api.getFundSettlement;
      if (!url) {
        axios.post(url, {}).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--工伤联网结算--错误!');
            console.log(res.data);
          }
          this.$refs.refCenter.initFundSettlement(res.data.result);
        }).catch(err => {});
      } else {
        this.$refs.refCenter.initFundSettlement();
      }
    },
    // 初始化图表数据--多跨协同
    initCooperation() {
      const url = api.getCooperation;
      if (url) {
        let param = {};
        param.areaCode = this.areaCode;
        param.startYear = this.firstMonth;
        param.endYear = this.lastMonth;
        axios.post(url, param).then(res => {
          if(res.data.code) {
            console.log('初始化图表数据--多跨协同--错误!');
            console.log(res.data);
          }
          this.$refs.refCenter.initCooperation(res.data.result);
        }).catch(err => {});
      } else {
        this.$refs.refCenter.initCooperation();
      }
    },
    // 子组件传来的地区编码
    setAreaCode(areaCode) {
      console.log(areaCode)
      this.areaCode = areaCode;
      this.initDataRight();
      this.initDataLeft();
      this.initDateCenter();
    },
    // 子组件传来的数据年份
    setDataYear(year) {
      console.log(year)
      this.year = year;
      this.initDataRight();
      this.initDataLeft();
      this.initDateCenter();
    }
  }
}
</script>

<style scoped >
* {
  margin: 0;
  padding: 0;
  font-family: 微软雅黑;
}

body {
  width: 100%;
  height: 100%;
}

.bg {
  background: url("../assets/bg.png") no-repeat;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-size: cover;
  position: fixed;
  margin-top: -60px;
  margin-left: -8px;
}

.btn_bottom :hover {
  color: #F9D494;
}

main {
  margin: 6% auto;
  height: 81%;
  width: 96%;
}

footer {
  background: url("../assets/footer.png") no-repeat;
  overflow: hidden;
  background-size: cover;
  height: 8.2%;
  width: 100%;
  position: absolute;
  bottom: 0;
}
</style>
